#include "Animation.h"

Animation::Animation(string nomeArq, float x, float y, int frameTime, int n) : Sprite(nomeArq, x, y)
{
    this->frameTime = frameTime;
    this->n = n;

    rectangle.w = (surface->w)/this->n;
    rectangle.h = surface->h;

    srcrect.x = 0;
    srcrect.y = 0;
    srcrect.w = rectangle.w;
    srcrect.h = rectangle.h;

    this->tempo = 0;
}

void Animation::Update(int dt)
{
    tempo = tempo + dt;
    saltoFrames = tempo / frameTime;
    tempo = tempo % frameTime;

    srcrect.x = srcrect.x + (srcrect.w*saltoFrames);

    if(srcrect.x >= surface->w)
    {
        srcrect.x = (srcrect.x - surface->w) % surface->w;
    }
}

void Animation::Render(SDL_Surface *screen)
{
    rectangle.x = x;
    rectangle.y = y;

    SDL_BlitSurface(surface, &srcrect, screen, &rectangle);

}
